﻿<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <script src="~/js/frame.js"></script>
    <style>
        .RoleCheckBoxContainer {
            margin: 5px;
        }
    </style>
</head>
<body>
    <div class="container-fluid">
        <form id="form">
            <div class="panel-group" id="elementright" aria-multiselectable="true">
                <div class="panel panel-default">
                    <div class="panel-heading" id="orgrighthead">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#elementright" href="#orgright">
                                组织架构授权
                            </a>
                        </h4>
                    </div>
                    <div id="orgright" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div style="display:flex;flex-direction:column">
                                <div>
                                    授权部门
                                </div>
                                <div>
                                    <cloud-tree id="ElementRightOU" url="tree" control-type="selectou" select-type="multi" style="height:50px"></cloud-tree>
                                </div>
                            </div>
                            <div style="display:flex;flex-direction:column">
                                <div>
                                    授权人员
                                </div>
                                <div>
                                    <cloud-tree id="ElementRightUser" url="tree" control-type="selectuser" select-type="multi" style="height:50px"></cloud-tree>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel-group" id="elementright" aria-multiselectable="true">
                <div class="panel panel-default">
                    <div class="panel-heading" id="orgrighthead">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#elementright" href="#orgright">
                                人员角色授权
                            </a>
                        </h4>
                    </div>
                    <div id="orgright" class="panel-collapse collapse in">
                        <div class="panel-body">
                            <div style="width:100%;display:flex;flex-direction:row;flex-wrap:wrap" id="RoleContainer">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row formbtnop">
                <button class="btn btn-primary cloudbtn" type="button" onclick="Save()">保 存</button>
                <button class="btn cloudbtn" type="button" onclick="Close()">关 闭</button>
            </div>
        </form>
    </div>
    <script>
        var validator = $("#form").validate();
        $(function () {
            LoadDetail();
            RenderTree();
        })
        function LoadDetail() {
            var param = { "ElementGuid": GetUrlParam("elementguid") }
            CloudPost(param, "getElementRightData", function (res) {
                $("#ElementRightOU").attr("selectvalue", res.data.OUGuidList);
                $("#ElementRightUser").attr("selectvalue", res.data.UserGuidList);
                RenderTree();
                CloudPost({}, getRootPath() + "frame/org/role/oplistall", function (RoleRes) {
                    var RoleHtml = "";
                    $(RoleRes.data).each(function (index, Role) {
                        if (res.data.RoleGuidList.indexOf(Role.RoleGuid) > -1) {
                            RoleHtml += "<div class='RoleCheckBoxContainer'><input type='checkbox' class='RoleCheckBox' checked RoleGuid='" + Role.RoleGuid + "' id=" + Role.RoleGuid + "><label for=" + Role.RoleGuid + ">" + Role.RoleName + "</label></div>";
                        } else {
                            RoleHtml += "<div class='RoleCheckBoxContainer'><input type='checkbox' class='RoleCheckBox'  RoleGuid='" + Role.RoleGuid + "'  id=" + Role.RoleGuid + "><label for=" + Role.RoleGuid + ">" + Role.RoleName + "</label></div>";
                        }
                    })
                    $("#RoleContainer").html(RoleHtml)
                })
            })


        }
        function Save() {
            var RoleGuidList = "";
            $(".RoleCheckBox").each(function () {
                if ($(this).prop('checked')) {
                    RoleGuidList += $(this).attr("RoleGuid")+";"
                }
            })
            var param = { "ElementGuid": GetUrlParam("elementguid"), "OUGuidList": GetTreeSelectValue("ElementRightOU"), "UserGuidList": GetTreeSelectValue("ElementRightUser"), "RoleGuidList": RoleGuidList }
            CloudPost(param, "updateElementRightData", function (res) {
                if (res.code == 0) {
                    OpenSuccess("保存成功", Close)
                }
            })
        }
        function Close() {
            CloseDialog();
        }
    </script>
</body>
</html>
